//
//  VistorLoginView.swift
//  WBPoject
//
//  Created by WorkSpace on 15/10/18.
//  Copyright © 2015年 商刻. All rights reserved.
//

import UIKit

protocol VistorLoginViewDelegate : NSObjectProtocol{

    func clickedLoginBtn()
    func clickedRegisterBtn()
}

class VistorLoginView: UIView{

    @IBOutlet weak var iconView: UIImageView!

    @IBOutlet weak var iconBgView: UIImageView!
    
    @IBOutlet weak var messageLable: UILabel!
    
    weak var delegete :VistorLoginViewDelegate?
    
    func setupInfo(iconViewName:String, message:String, isHome:Bool=false){
    
    
        if isHome {
        
            iconView.hidden = false
            iconView.image = UIImage(named: iconViewName)
            startAnimation()
        }else{
        
            iconView.hidden = true
            iconBgView.image = UIImage(named: iconViewName)
            stopAnimation()
        }
        messageLable.text = message
    }
    
    func startAnimation(){
    
        let animation = CABasicAnimation(keyPath:  "transform.rotation")
        animation.toValue = 2 * M_1_PI
        animation.repeatCount = MAXFLOAT
        animation.duration = 10
        iconBgView.layer.addAnimation(animation, forKey: nil)
    }
    
    func stopAnimation(){
    
        iconBgView.layer.removeAllAnimations()
    }
    
    @IBAction func loginBtnClicked(sender: UIButton) {
        
        delegete?.clickedLoginBtn()
    }
    
    @IBAction func registerBtnClicked(sender: UIButton) {
        
        delegete?.clickedRegisterBtn()
    }
    
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
